import { View } from "../../../mvc/core/View";
import { IPetHirePanel } from "./IPetHirePanel";
import { Language } from "../../../../extend/language/Language";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { PetHireSortType } from "./PetHireSortType";
import { EPetRentQueryOrder } from "../../../../Message/Game/EPetRentQueryOrder";
import { PageTool } from "../../../common/global/PageTool";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { RadioButtonGroup } from "../../../../fl/controls/RadioButtonGroup";
import { ObjCreate } from "../common/ObjCreate";
import { TilePanel } from "../equipment/TilePanel";
import { PetHireMarketRenderer } from "./PetHireMarketRenderer";
import { ComboBoxItemCellRender } from "../lock/ComboBoxItemCellRender";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { TimeButton } from "../common/button/TimeButton";
import { ImagesConst } from "../../resource/ImagesConst";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
import { Cache } from "../../cache/Cache";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GRadioButton } from "../../../../com/mui/controls/GRadioButton";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GComboBox } from "../../../../com/mui/controls/GComboBox";
import { ApplyDateDesc } from "../../../../PetHireSortType/ApplyDateDesc";
import { _EPetRentQueryOrderTimeDsc } from "../../../../EPetRentQueryOrder/_EPetRentQueryOrderTimeDsc";
import { ApplyDateAsc } from "../../../../PetHireSortType/ApplyDateAsc";
import { _EPetRentQueryOrderTimeAsc } from "../../../../EPetRentQueryOrder/_EPetRentQueryOrderTimeAsc";
import { HirePriceDesc } from "../../../../PetHireSortType/HirePriceDesc";
import { _EPetRentQueryOrderPriceDsc } from "../../../../EPetRentQueryOrder/_EPetRentQueryOrderPriceDsc";
import { HirePriceAsc } from "../../../../PetHireSortType/HirePriceAsc";
import { _EPetRentQueryOrderPriceAsc } from "../../../../EPetRentQueryOrder/_EPetRentQueryOrderPriceAsc";
type int = number;
//class PetHireMarketPanel
    
    export  class PetHireMarketPanel extends View implements IPetHirePanel
    {
        constructor()
        {
            this._tip = Language.getString(54351);
            this._sortDp = new DataProvider([{"label": ApplyDateDesc, "value": _EPetRentQueryOrderTimeDsc}, {"label": ApplyDateAsc, "value": _EPetRentQueryOrderTimeAsc}, {"label": HirePriceDesc, "value": _EPetRentQueryOrderPriceDsc}, {"label": HirePriceAsc, "value": _EPetRentQueryOrderPriceAsc}]);
            this._searchLableArray = Language.getString(54352).split(",");
            this._cbArray = [];
            this._vInputArray = [];
            this._pageTool = new PageTool([], 3);
            super();
            this.init();
            return;
        }

        /* internal  */onPageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this._cpage = this._pageBar.currentPage;
            this.doSearch(this._cpage);
            return;
        }

        /* internal  */updateByArray(arg1: Array<any>): void
        {
            this._hireList.dataProvider.removeAll();
            var loc1=0;
            while (loc1 < arg1.length) 
            {
                this._hireList.dataProvider.addItem(arg1[loc1]);
                ++loc1;
            }
            return;
        }

        /* internal  */onShowSearchBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._searchPanel.visible = !this._searchPanel.visible;
            return;
        }

        /* internal  */onInputChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=arg1.target as GTextInput;
            if (loc1.text == "" || int(loc1.text) == 0) 
            {
                loc1.text = "1";
            }
            return;
        }

        /* internal  */onRefreshBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.onNormalSearchHandler(null);
            return;
        }

        /* internal  */init(): void
        {
            var loc2=0;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            this._unitRadioGroup = new RadioButtonGroup("unit");
            this._topPanel = new Object /* flash.display.Sprite */();
            this.addChild(this._topPanel);
            this._showCheckBox = ObjCreate.createCheckBox(Language.getString(54353), 8, 5, 120, 28, this._topPanel);
            this._showCheckBox.selected = false;
            this._showCheckBox.visible = false;
            this._showCheckBox.addEventListener(flash.events.MouseEvent.CLICK, this.onNormalSearchHandler);
            this._allRadio = ObjCreate.createRadioButton(Language.getString(54595), 230, 5, 100, 28, this._topPanel);
            this._allRadio.selected = true;
            this._allRadio.group = this._unitRadioGroup;
            this._coinRadio = ObjCreate.createRadioButton(Language.getString(54354), 315, 5, 100, 28, this._topPanel);
            this._coinRadio.group = this._unitRadioGroup;
            this._goldRadio = ObjCreate.createRadioButton(Language.getString(54355), 400, 5, 100, 28, this._topPanel);
            this._goldRadio.group = this._unitRadioGroup;
            this._allRadio.addEventListener(flash.events.MouseEvent.CLICK, this.onNormalSearchHandler);
            this._coinRadio.addEventListener(flash.events.MouseEvent.CLICK, this.onNormalSearchHandler);
            this._goldRadio.addEventListener(flash.events.MouseEvent.CLICK, this.onNormalSearchHandler);
            this._showSearchBtn = ObjCreate.createGButton(Language.getString(54356), 515, 5, 70, 24, this._topPanel);
            this._showSearchBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onShowSearchBtnClickHandler);
            this._hireList = new TilePanel();
            this._hireList.setStyle("cellRenderer", PetHireMarketRenderer);
            this._hireList.columnWidth = 590;
            this._hireList.rowHeight = 95;
            this._hireList.setSize(595, 285);
            this._hireList.move(0, 35);
            this.addChild(this._hireList);
            this._sortComboBox = ObjCreate.createGComboBox(0, 317, 150, 25, this._sortDp, this);
            this._sortComboBox.dropdown.width = 150;
            this._sortComboBox.dropdown.setStyle("cellRenderer", ComboBoxItemCellRender);
            this._sortComboBox.addEventListener(flash.events.Event.CHANGE, this.onNormalSearchHandler);
            this._pageBar = ObjCreate.createPageSelecter(230, 325, this);
            this._pageBar.mode = PageSelecter.CompleteMode;
            this._pageBar.addEventListener(flash.events.Event.CHANGE, this.onPageChangeHandler);
            this._refreshBtn = new TimeButton(5);
            this._refreshBtn.styleName = "Button";
            this._refreshBtn.label = Language.getString(54357);
            this._refreshBtn.setSize(60, 24);
            this._refreshBtn.move(515, 317);
            this.addChild(this._refreshBtn);
            this._refreshBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onRefreshBtnClickHandler);
            this._searchPanel = new Object /* flash.display.Sprite */();
            this._searchPanel.x = 605;
            this._searchPanel.y = -13;
            ObjCreate.createBg(0, 0, 175, 150, this._searchPanel, ImagesConst.WindowCenterA);
            var loc1=0;
            while (loc1 < this._searchLableArray.length) 
            {
                loc2 = loc1 * 25 + 15;
                loc3 = ObjCreate.createCheckBox("", 15, loc2, 95, 20, this._searchPanel);
                (loc4 = ObjCreate.createTextField("", 35, loc2, 70, 20, this._searchPanel)).htmlText = HTMLUtil.addColor(this._searchLableArray[loc1] as string, GlobalStyle.color6) + HTMLUtil.addColor("达到", GlobalStyle.color1);
                (loc5 = ObjCreate.createGTextInput(95, loc2, 55, 20, this._searchPanel)).restrict = "0-9";
                loc5.maxChars = 4;
                loc5.addEventListener(flash.events.Event.CHANGE, this.onInputChangeHandler);
                this._cbArray.push(loc3);
                this._vInputArray.push(loc5);
                ++loc1;
            }
            this.searchResetDefault();
            this._searchBtn = ObjCreate.createGButton(Language.getString(54358), 60, 115, 60, 24, this._searchPanel);
            this._searchBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onSearchBtnClickHandler);
            this._searchPanel.visible = false;
            this.addChild(this._searchPanel);
            this._tipTxt = ObjCreate.createTextField("", 0, 145, 600, 50, this, new GTextFormat(FontUtil.songtiName, 16, 15788607));
            this._tipTxt.visible = false;
            this._tipTxt.multiline = true;
            this._tipTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._tipTxt.htmlText = "<textFormat leading=\'5\'>" + this._tip + "</textFormat>";
            return;
        }

        public updateDataProvider(arg1: Array<any>, arg2: int, arg3: int=1): void
        {
            this._pageTool.array = arg1;
            this._pageBar.currentPage = arg3;
            this._pageBar.maxPage = arg2;
            this.updateByArray(arg1);
            if (arg1.length > 0) 
            {
                this._tipTxt.visible = false;
            }
            else 
            {
                this._tipTxt.visible = true;
            }
            return;
        }

        public resetPanel(): void
        {
            this._showCheckBox.selected = true;
            this._allRadio.selected = true;
            this._coinRadio.selected = false;
            this._goldRadio.selected = false;
            this._sortComboBox.selectedIndex = 0;
            this._searchPanel.visible = false;
            this.searchResetDefault();
            return;
        }

        public refresh(): void
        {
            this.onNormalSearchHandler(null);
            return;
        }

        /* internal  */searchResetDefault(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            while (loc3 < this._cbArray.length) 
            {
                loc1 = this._cbArray[loc3] as GCheckBox;
                loc1.selected = true;
                loc2 = this._vInputArray[loc3] as GTextInput;
                if (loc3 != 0) 
                {
                    if (loc3 != 1) 
                    {
                        if (loc3 != 2) 
                        {
                            loc2.text = "10";
                        }
                        else 
                        {
                            loc2.text = "20";
                        }
                    }
                    else 
                    {
                        loc2.text = "800";
                    }
                }
                else 
                {
                    loc2.text = Cache.instance.role.entityInfo.level.toString();
                }
                ++loc3;
            }
            return;
        }

        /* internal  */onSearchBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._isAdvancedSearch = true;
            this.doSearch();
            return;
        }

        /* internal  */onNormalSearchHandler(arg1: Object /* flash.events.Event */): void
        {
            this._isAdvancedSearch = false;
            this.doSearch();
            return;
        }

        /* internal  */doSearch(arg1: int=1): void
        {
            var loc7=0;
            var loc8=0;
            var loc9=0;
            var loc10=0;
            var loc11=null;
            var loc12=0;
            var loc1=this._showCheckBox.selected;
            var loc2=this._allRadio.selected;
            var loc3=this._goldRadio.selected;
            var loc4=this._coinRadio.selected;
            if (loc2) 
            {
                loc3 = false;
                loc4 = false;
            }
            var loc5=this._sortComboBox.selectedItem.value;
            var loc6=arg1;
            if (this._isAdvancedSearch) 
            {
                loc12 = 0;
                while (loc12 < this._cbArray.length) 
                {
                    if ((loc11 = this._cbArray[loc12] as GCheckBox).selected) 
                    {
                        if (loc12 != 0) 
                        {
                            if (loc12 != 1) 
                            {
                                if (loc12 != 2) 
                                {
                                    loc10 = int((this._vInputArray[loc12] as GTextInput).text);
                                }
                                else 
                                {
                                    loc9 = int((this._vInputArray[loc12] as GTextInput).text);
                                }
                            }
                            else 
                            {
                                loc8 = int((this._vInputArray[loc12] as GTextInput).text);
                            }
                        }
                        else 
                        {
                            loc7 = int((this._vInputArray[loc12] as GTextInput).text);
                        }
                    }
                    ++loc12;
                }
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetHireSearch, {"level": loc7, "talent": loc8, "spirit": loc10, "growth": loc9, "queryOrder": loc5, "targetPage": loc6, "isAbleHire": loc1, "isOnlyGold": loc3, "isOnlyCoin": loc4}));
            return;
        }

        /* internal */ /* var */_topPanel: Object /* flash.display.Sprite */;

        /* internal */ /* var */_showCheckBox: GCheckBox;

        /* internal */ /* var */_unitRadioGroup: RadioButtonGroup;

        /* internal */ /* var */_allRadio: GRadioButton;

        /* internal */ /* var */_coinRadio: GRadioButton;

        /* internal */ /* var */_goldRadio: GRadioButton;

        /* internal */ /* var */_showSearchBtn: GButton;

        /* internal */ /* var */_searchPanel: Object /* flash.display.Sprite */;

        /* internal */ /* var */_hireList: TilePanel;

        /* internal */ /* var */_sortComboBox: GComboBox;

        /* internal */ /* var */_pageBar: PageSelecter;

        /* internal */ /* var */_refreshBtn: TimeButton;

        /* internal */ /* var */_searchBtn: GButton;

        /* internal */ /* var */_tipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_tip: string;

        /* internal */ /* var */_sortDp: DataProvider;

        /* internal */ /* var */_searchLableArray: Array<any>;

        /* internal */ /* var */_vInputArray: Array<any>;

        /* internal */ /* var */_isAdvancedSearch: Boolean=false;

        /* internal */ /* var */_pageTool: PageTool;

        /* internal */ /* var */_cpage: int=1;

        /* internal */ /* var */_cbArray: Array<any>;
    }
